﻿// 功能：GridMenu控件的展示窗口
// 描述：
// 作者：温伟鹏
// 日期：2010/5/13 11:11:02

using System;
using MeizuSDK.Presentation;
using MeizuSDK.Drawing;

namespace Demo
{
    /// <summary>
    /// GridMenu控件的展示窗口
    /// </summary>
    class GridMenuWindow : DemoWindowBase
    {
        private ImageContainer imgContainer;

        private int DefaultGridMenuId = 1000;

        private ImagingHelper img1;
        private ImagingHelper img1Pressed;
        private ImagingHelper img2;
        private ImagingHelper img2Pressed;
        private ImagingHelper img3;
        private ImagingHelper img3Pressed;
        private ImagingHelper img4;
        private ImagingHelper img4Pressed;

        private GridMenu menu;

        public GridMenuWindow()
        {
            imgContainer = new ImageContainer();

            img1 = imgContainer.LoadImageFromMzResV2(MzResV2.Png_Tick, true);
            img1Pressed = imgContainer.LoadImageFromMzResV2(MzResV2.Png_Tick_Pressed, true);
            img2 = imgContainer.LoadImageFromMzResV2(MzResV2.Png_Download, true);
            img2Pressed = imgContainer.LoadImageFromMzResV2(MzResV2.Png_Download_Pressed, true);
            img3 = imgContainer.LoadImageFromMzResV2(MzResV2.Png_Cancel, true);
            img3Pressed = imgContainer.LoadImageFromMzResV2(MzResV2.Png_Cancel_Pressed, true);
            img4 = imgContainer.LoadImageFromMzResV2(MzResV2.Png_Search, true);
            img4Pressed = imgContainer.LoadImageFromMzResV2(MzResV2.Png_Search_Pressed, true);

            menu = new GridMenu();
            //menu.ItemClicked += new GridMenuItemClickedEventHandler(menu_ItemClicked);

            GridMenuItem item = new GridMenuItem(DefaultGridMenuId + 1, "菜单项1", img1, img1Pressed);
            menu.Items.Add(item);
            item = new GridMenuItem(DefaultGridMenuId + 2, "菜单项2", img2, img2Pressed);
            menu.Items.Add(item);
            item = new GridMenuItem(DefaultGridMenuId + 3, "菜单项3", img3, img3Pressed);
            menu.Items.Add(item);
            item = new GridMenuItem(DefaultGridMenuId + 4, "菜单项4", img4, img4Pressed);
            menu.Items.Add(item);

            Controls.Add(menu);

            toolbar.SetTextButton(ToolBarButtonIndex.MiddleTextButton, true, true, "Open GridMenu");
        }

        protected override void toolbar_ButtonClick(object sender, ToolBar.ButtonEventArgs e)
        {
            base.toolbar_ButtonClick(sender, e);

            if (e.Index == ToolBarButtonIndex.MiddleTextButton)
            {
                if(menu.IsContinue())
                {
                    menu.Close();
                }
                else
                {
                    menu.Show(HWnd,ToolBar.HEIGHT);
                }

                return;
            }

            if(menu.IsContinue())
            {
                menu.Close();
            }
        }

        protected override void OnMzCommand(uint wParam, uint lParam)
        {
            int id = (int)NativeMethods.LOWORD(wParam);

            GridMenuItem item = menu.Items[id];

            if(item!=null)
            {
                MessageBox.Show(string.Format("您点击了ID为[{0}]的菜单项[{1}]。", item.ItemId, item.Text), "GridMenu");
            }

            base.OnMzCommand(wParam, lParam);
        }
    }
}
